﻿using System;
using System.Web.UI;
using Token.Piker.Common;

namespace Token.Piker.Web.Admin.Tag
{
    public partial class Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int ID = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(ID);
                }
            }
        }

        private void ShowInfo(int ID)
        {
            Token.Piker.BLL.TagBLL bll = new Token.Piker.BLL.TagBLL();
            Token.Piker.Model.Tag model = bll.GetModel(ID);
            this.txtTagName.Text = model.TagName;
            this.ddlFlag.SelectedIndex = Convert.ToInt32(model.Flag);

        }

        protected void btnModify_Click(object sender, EventArgs e)
        {
            if (Session[GlobalConstants.PIKER_ADMIN] == null)
            {
                MessageBox.ShowAndRedirect(this.Page, "网络连接超时，请重新登录！", ResolveClientUrl("~/Admin/Login.aspx"));
                return;
            }
            string TagName = this.txtTagName.Text;
            int Adder = Convert.ToInt32(Session[GlobalConstants.PIKER_ADMIN]);
            DateTime AddTime = DateTime.Now;
            int Flag = int.Parse(ddlFlag.SelectedValue);
            Token.Piker.BLL.TagBLL bll = new Token.Piker.BLL.TagBLL();
            Token.Piker.Model.Tag model = bll.GetModel(Adder);
            model.TagName = TagName;
            model.Adder = Adder;
            model.AddTime = AddTime;
            model.Flag = Flag;

            bll.Update(model);
            MessageBox.ShowAndRedirect(this, "修改成功！", "List.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }

    }
}